﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using BugNET.Common;
using BugNET.Entities;

namespace BugNET.Providers.DataProviders
{
    public partial class SqlDataProvider
    {
        public override List<DashBoard> GetDashBoard_ClosureState(Int32 ProjectId, Int32 MileStoneId, string UserName)
        {
            using (var sqlCmd = new SqlCommand())
            {
                AddParamToSqlCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, ProjectId);
                AddParamToSqlCmd(sqlCmd, "@UserName", SqlDbType.Text, 0, ParameterDirection.Input, UserName);
                AddParamToSqlCmd(sqlCmd, "@MileStoneId", SqlDbType.Int, 0, ParameterDirection.Input, MileStoneId);               
                
                SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_DASHBOARD_CLOSESTATE);

                var lstDashBoardData = new List<DashBoard>();
                ExecuteReaderCmd(sqlCmd, Get_DashboardaData_Close_State_FromReader, ref lstDashBoardData);
                return lstDashBoardData;
            }
        }

        public override List<DashBoard> GetDashBoard_Status(int projectId, int mileStoneId, int priorityId, int categoryId, int typeId, DateTime startDate, DateTime endDate)
        {
            using (var sqlCmd = new SqlCommand())
            {
                AddParamToSqlCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, projectId);
                AddParamToSqlCmd(sqlCmd, "@MileStoneId", SqlDbType.Int, 0, ParameterDirection.Input, mileStoneId);
                AddParamToSqlCmd(sqlCmd, "@PriorityId", SqlDbType.Int, 0, ParameterDirection.Input, priorityId);
                AddParamToSqlCmd(sqlCmd, "@CategoryId", SqlDbType.Int, 0, ParameterDirection.Input, categoryId);
                AddParamToSqlCmd(sqlCmd, "@TypeId", SqlDbType.Int, 0, ParameterDirection.Input, typeId);
                AddParamToSqlCmd(sqlCmd, "@StartDate", SqlDbType.DateTime, 0, ParameterDirection.Input, startDate);
                AddParamToSqlCmd(sqlCmd, "@EndDate", SqlDbType.DateTime, 0, ParameterDirection.Input, endDate);

                SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_DASHBOARD_STATUS);

                var lstDashBoardData = new List<DashBoard>();
                ExecuteReaderCmd(sqlCmd, Get_DashboardaData_Status_FromReader, ref lstDashBoardData);
                return lstDashBoardData;
            }
        }
        public override List<DashBoard> GetDashBoard_Resolution(int projectId, int mileStoneId, int priorityId, int categoryId, int typeId, DateTime startDate, DateTime endDate)
        {

            using (var sqlCmd = new SqlCommand())
            {
                AddParamToSqlCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, projectId);
                AddParamToSqlCmd(sqlCmd, "@MileStoneId", SqlDbType.Int, 0, ParameterDirection.Input, mileStoneId);
                AddParamToSqlCmd(sqlCmd, "@PriorityId", SqlDbType.Int, 0, ParameterDirection.Input, priorityId);
                AddParamToSqlCmd(sqlCmd, "@CategoryId", SqlDbType.Int, 0, ParameterDirection.Input, categoryId);
                AddParamToSqlCmd(sqlCmd, "@TypeId", SqlDbType.Int, 0, ParameterDirection.Input, typeId);
                AddParamToSqlCmd(sqlCmd, "@StartDate", SqlDbType.DateTime, 0, ParameterDirection.Input, startDate);
                AddParamToSqlCmd(sqlCmd, "@EndDate", SqlDbType.DateTime, 0, ParameterDirection.Input, endDate);

                SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_DASHBOARD_RESOLUTION);

                var lstDashBoardData = new List<DashBoard>();
                ExecuteReaderCmd(sqlCmd, Get_DashboardaData_Resolution_FromReader, ref lstDashBoardData);
                return lstDashBoardData;
            }
        }
    }
}
